package mazeMultiThread;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * Controls global variables to synchronize properties between threads
 * @author Dani
 *
 */
public class VentanaKeyboardListener implements KeyListener {

	@Override
	public void keyPressed(KeyEvent arg0) {
		//decrease speed of generation
		if (arg0.getKeyCode() == KeyEvent.VK_X) 
			GH.MAZE_SLOWNESS++;
		//increase speed of generation unless it is at max speed
		if (arg0.getKeyCode() == KeyEvent.VK_Z)
			if (GH.MAZE_SLOWNESS > 0) 
				GH.MAZE_SLOWNESS--;
		
		//zoom in the maze
		if (arg0.getKeyCode() == KeyEvent.VK_I) 
			GH.scaleUp();
		//zoom out of the maze
		if (arg0.getKeyCode() == KeyEvent.VK_O) 
			GH.scaleDown();
		
		//move up
		if (arg0.getKeyCode() == KeyEvent.VK_W)
			GH.yStart+=10*(GH.scY);
		//move down
		if (arg0.getKeyCode() == KeyEvent.VK_S)
			GH.yStart-=10*(GH.scY);
		//move left
		if (arg0.getKeyCode() == KeyEvent.VK_A)
			GH.xStart+=10*(GH.scX);
		//move right
		if (arg0.getKeyCode() == KeyEvent.VK_D)
			GH.xStart-=10*(GH.scX);
		
		//reset the position of the maze to the center. If shift is pressed at the same time, reset the zoom too
		if (arg0.getKeyCode() == KeyEvent.VK_C) {
			if (arg0.isShiftDown()) {
				GH.scX = 1;
				GH.scY = 1;
			}
			GH.xStart = 0;
			GH.yStart = 0;
		}
		
		//restart the maze generation with a brand new seed
		if (arg0.getKeyCode() == KeyEvent.VK_R) 
			GH.RESTART = true;
		//pause generation or resume generation
		if (arg0.getKeyCode() == KeyEvent.VK_P) 
			GH.PAUSE = !GH.PAUSE;
		
		//iterate the generation algorithm (if paused) 1 time or 10 times if shift was pressed
		if (arg0.getKeyCode() == KeyEvent.VK_N)
			if (GH.PAUSE)
				if (arg0.isShiftDown())
					GH.STEP+=10;
				else
					GH.STEP++;
		//iterate the generation algorithm (if paused) 5 times or 100 times if shift was pressed
		if (arg0.getKeyCode() == KeyEvent.VK_M)
			if (GH.PAUSE)
				if (arg0.isShiftDown())
					GH.STEP+=100;
				else
					GH.STEP+=5;	
		
	}
	
	//unused methods below

	@Override
	public void keyReleased(KeyEvent arg0) {
		return;
	}
	@Override
	public void keyTyped(KeyEvent arg0) {
		return;
	}

}

